
/**
 *  针对单条快讯进行的统计，按天统计
 */
module.exports = function (mongoose, Schema) {
    let ObjectId = Schema.Types.ObjectId;
    let schema = new Schema({
        //  文章Id
        fid: {
            type: ObjectId
        },
        //  日期
        date: String,
        //  查看次数
        viewCount: Number,
        //  实际查看次数
        realViewCount: Number,
        //  点赞次数
        topCount: Number,
        //  取消点赞次数
        delTopCount: Number,
        //  收藏次数
        collectCount: Number,
        //  取消收藏次数
        delCollectCount: Number,
        //  分享次数
        shareCount: Number,
        //  我来播次数
        playCount: Number
        //
    }, {collection: 'fast_statistics_day', timestamps: true});

    schema.index({date: 1});
    schema.index({fid: 1});

    schema.statics = {
        //  根据type进行操作
        operateByType: (type)=> {
            let operate = {};
            switch (type) {
                //  查看
                case 'viewCount':
                    operate = {$inc: {viewCount: 1}};
                    break;
                case 'realViewCount':
                    operate = {$inc: {realViewCount: 1}};
                    break;
                case 'topCount':
                    operate = {$inc: {topCount: 1}};
                    break;
                case 'delTopCount':
                    operate = {$inc: {delTopCount: 1}};
                    break;
                case 'collectCount':
                    operate = {$inc: {collectCount: 1}};
                    break;
                case 'delCollectCount':
                    operate = {$inc: {delCollectCount: 1}};
                    break;
                case 'playCount':
                    operate = {$inc: {playCount: 1}};
                    break;
                case 'shareCount':
                    operate = {$inc: {shareCount: 1}};
                    break;
            }
            return operate
        }
    };

    return mongoose.model('FastStatisticsDay', schema);
};

